package sample.stock;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class EODChart extends Activity {
    private WebView webView = null;
    private String symbol;
    private String exchange;
   
    private static final String base_URL = "http://chart.eoddata.com/";
    
    final Activity activity = this;
	 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.eodchart);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        
        webView = (WebView)findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        
        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);
 
                if(progress == 100)
                    activity.setTitle("EOD Chart");
            }
        });
        
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }
 
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });
        
        Bundle extras = getIntent().getExtras(); 
        symbol = extras.getString("symbol");
        exchange = extras.getString("exchange");
        
        String url = base_URL;
        url += "?e=" + exchange;
        url += "&s=" + symbol + "&w=490&h=400&t=1&bs=candle&ma=5-20&mat=SMA-SMA&i=MACD&b=BB";
        
        webView.loadUrl(url);
    }
}
